package networkTraining.algorithms;

import java.util.Map;

import neuralModel.neuron.INeuron;
import neuralModel.neuron.ISignal;
import neuralNetwork.INeuralNetwork;

public class LinearOuputLayerTrainer implements ITrainingAlgorithm
{

	public INeuralNetwork neuralNetwork;
	public double learnRate;

	public LinearOuputLayerTrainer(INeuralNetwork neuralNetwork, double learingRate)
	{
		this.neuralNetwork = neuralNetwork;
		this.learnRate = learingRate;
	}

	@Override
	public void trainNeuralNetwork(Map<String, Double> errorMap)
	{
		INeuron neuron;
		for (String name : errorMap.keySet())
		{
			neuron = neuralNetwork.getNeuron(name);
			for (ISignal signal : neuron.getInputSignalList())
			{
				double oldWeight = signal.getWeight();
				double error = errorMap.get(name);
				double newWeight = oldWeight + learnRate * (error * signal.getSignalValue());
				signal.setWeight(newWeight);
			}

		}
	}

}
